<%-- 
    Document   : AddRoom
    Created on : Apr 1, 2014, 4:47:46 PM
    Author     : Mukesh
--%>

<%@page import="java.util.Iterator"%>
<%@page import="Hostel.HostelBean"%>
<%@page import="java.util.Vector"%>
<%
    try {
        if (session.getAttribute("uid") != null) {
            if (session.getAttribute("Room").toString().equals("1")) {
%>
<%String to = "", status = "", msg = "", admissionId = "";%>
<!DOCTYPE html>
<html>
    <head>
        <title>Ramgovind Automated System</title>

        <link rel="stylesheet" href="/RIT/css/bootstrap.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap-responsive.css">
        <link rel="stylesheet" href="/RIT/css/jquery.fancybox.css">
        <link rel="stylesheet" href="/RIT/css/style.css">
        <link rel="stylesheet" href="/RIT/css/iconfont.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap.datepicker.css">
        <script src="../../ajax/ajax.js"></script>
        <script>
            function getRooms(val){
                var hid=document.getElementById('hname').value;
                if(hid!="")
                {
                    var xmlhttp; 
                    if (window.XMLHttpRequest)
                    {
                        xmlhttp=new XMLHttpRequest();
                    }
                    else
                    {
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    xmlhttp.onreadystatechange=function()
                    { 
                        if (xmlhttp.readyState==4 && xmlhttp.status==200)
                        {
                            document.getElementById('rm').innerHTML = xmlhttp.responseText;  
                        }
                    }
                    xmlhttp.open("POST","/RIT/RoomNumber?no="+val+"&hid="+hid+"&rno=1",true);
                    xmlhttp.send();
                }
                else
                {
                    alert("Please Select Hostel");
                }
            }
            function checkRoomAllot(val){
                var xmlhttp; 
                if (window.XMLHttpRequest)
                {
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                { 
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        if(xmlhttp.responseText!=0){
                            document.getElementById('hid').innerHTML='<div class="alert alert-info alert-block" id="hid"><a class="close" data-dismiss="alert" href="#"><img src="/RIT/img/mclose.png"></a><h4 class="alert-heading" id="msg">Fail</h4>This Hostel Already Exist!!</div>';
                            document.getElementById('sub').disabled=true;
                            document.getElementById('roomNo').readOnly=true;
                        }else{
                            document.getElementById('sub').disabled=false;
                            document.getElementById('roomNo').readOnly=false;
                        }
                    }
                }
                xmlhttp.open("POST","/RIT/CheckRoomAllotment?val="+val,true);
                xmlhttp.send();
            }
        </script>

    </head>
    <body>
        <%@include file="/topheader.html" %>
        <%@include file="/settingheader.html" %>
        <div class="main">
            <div class="container-fluid">
                <%@include file="/Settings/dbsidenav.html" %>
                <div class="content">
                    <div id="hid"></div>
                    <%if (session.getAttribute("status") != null) {
                            status = session.getAttribute("status").toString();
                            msg = session.getAttribute("msg").toString();
                    %>
                    <div class="alert alert-info alert-block">
                        <a class="close" data-dismiss="alert" href="#"><img src="/RIT/img/mclose.png"></a>
                        <h4 class="alert-heading"> <%=status%></h4>
                        <%=msg%>

                    </div>
                    <%session.removeAttribute("status");
                            session.removeAttribute("msg");
                        }%>
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="box">
                                <div class="box-head">
                                    <h3>Room Information</h3>
                                    <a href="/RIT/Settings/Database/Room.jsp">
                                        <button style="float: right" class="btn btn-success">View Hostel</button>
                                    </a>
                                </div>

                                <form action="/RIT/AddRoom" method="post" class='validate form-horizontal'>
                                    <div class="box-content">
                                        <!---Form Start....-->
                                        <legend>
                                            Hostel Details
                                        </legend>
                                        <div id="lside" style="float: left; margin-top: 10px; width: 48%;">
                                            <div class="control-group">
                                                <label for="hname" class="control-label">Hostel Name<span style="color:red">*</span></label>
                                                <div class="controls">
                                                    <select name="hname" id="hname" onchange="checkRoomAllot(this.value)">
                                                        <option value="">Select Hostel</option>
                                                        <%{
                                                                Vector<Object> list = Hostel.Query.ViewAll();
                                                                Iterator it = list.iterator();

                                                                while (it.hasNext()) {
                                                                    HostelBean hb = (HostelBean) it.next();
                                                        %>
                                                        <option value="<%=hb.getHotelId()%>"><%=hb.getHostelName()%></option>
                                                        <%}
                                                            }%>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div id="rside" style="float: left; margin-right: 0px; margin-top: 10px">
                                            <div class="control-group">
                                                <label for="roomNo" class="control-label">Number of Rooms</label>
                                                <div class="controls">
                                                    <div class="span3">
                                                        <input type="text" name="roomNo" id="roomNo" onblur="getRooms(this.value)">
                                                        <input type="hidden" name="rno" id="rno" value="0">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div id="rm">
                                        </div>
                                        <!---Form Ends....-->
                                    </div>
                                    <div class="form-actions">
                                        <input type="submit" name="sub" id="sub" class='btn btn-primary'>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                </div>	
            </div>
        </div>

        <script src="/RIT/js/jquery.js"></script>
        <script src="/RIT/js/less.js"></script>
        <script src="/RIT/js/bootstrap.min.js"></script>
        <script src="/RIT/js/jquery.uniform.min.js"></script>
        <script src="/RIT/js/bootstrap.timepicker.js"></script>
        <script src="/RIT/js/bootstrap.datepicker.js"></script>
        <script src="/RIT/js/chosen.jquery.min.js"></script>
        <script src="/RIT/js/jquery.fancybox.js"></script>
        <script src="/RIT/js/plupload/plupload.full.js"></script>
        <script src="/RIT/js/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
        <script src="/RIT/js/jquery.cleditor.min.js"></script>
        <script src="/RIT/js/jquery.inputmask.min.js"></script>
        <script src="/RIT/js/jquery.tagsinput.min.js"></script>
        <script src="/RIT/js/jquery.mousewheel.js"></script>
        <script src="/RIT/js/jquery.textareaCounter.plugin.js"></script>
        <script src="/RIT/js/ui.spinner.js"></script>
        <script src="/RIT/js/jquery.jgrowl_minimized.js"></script>
        <script src="/RIT/js/jquery.form.js"></script>
        <script src="/RIT/js/jquery.validate.min.js"></script>
        <script src="/RIT/js/bbq.js"></script>
        <script src="/RIT/js/jquery-ui-1.8.22.custom.min.js"></script>
        <script src="/RIT/js/jquery.form.wizard-min.js"></script>
        <script src="/RIT/js/jquery.cookie.js"></script>
        <script src="/RIT/js/jquery.metadata.js"></script>
        <script src="/RIT/js/custom.js"></script><script src="/RIT/js/demo.js"></script>
        <script src="/RIT/js/iconfont.js"></script>
    </body>
</html>
<%
} else {
    out.println("<script>alert('" + session.getAttribute("Enquiry") + "')</script>");
%>
<script type="text/javascript">
    alert("You Are Not Authorised");
    window.history.back();
</script>
<%
            }
        } else {
            request.setAttribute("msg", "You Are Not Authorised! Please Contact to System Administrator!");
            request.setAttribute("value", "0");
            getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
        }
    } catch (Exception e) {
        request.setAttribute("msg", "Please Contact to System Administrator!");
        request.setAttribute("value", "0");
        getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
    }
%>


